package com.lgmshare.k3.manager;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.lgmshare.k3.model.UserInfo;
import com.lgmshare.k3.ui.AppScopeViewModel;

public class UserInfoViewModel extends ViewModel implements AppScopeViewModel, OnUserInfoUpdateListener {

    private MutableLiveData<Boolean> mUserLoginStatusLiveData = new MutableLiveData<>();
    private MutableLiveData<UserInfo> mUserInfoLiveData = new MutableLiveData<>();

    public UserInfoViewModel() {
        AppDataSyncManager.getInstance().addUserInfoUpdateListener(this);
    }

    @Override
    protected void onCleared() {
        AppDataSyncManager.getInstance().removeUserInfoUpdateListener(this);
    }

    public MutableLiveData<Boolean> userLoginStatusLiveData() {
        return mUserLoginStatusLiveData;
    }

    public MutableLiveData<UserInfo> userInfoLiveData() {
        return mUserInfoLiveData;
    }

    @Override
    public void onUserLoginStatusChange(boolean login) {
        mUserLoginStatusLiveData.postValue(login);
    }

    @Override
    public void onUserInfoChange(UserInfo userInfo) {
        mUserInfoLiveData.postValue(userInfo);
    }
}
